// 导入 path 模块
const path = require( 'path' );
// 导入 express 模块
const express = require( 'express' );

const port = 8080 ;
const app = express();

// 处理静态资源
const assets = path.resolve( 'public' );
const assetsHandler = express.static( assets );
app.use( assetsHandler );

// 处理POST方式提交的表单数据
const bodyHandler = express.urlencoded( { extended: false } );
app.use( bodyHandler );

const handler = (req,resp) => {
    console.log( req.protocol , req.method , req.url );
    console.log( 'query string : ' , req.query );
    console.log( 'request body : ' ,  req.body );

    let today = new Date();
    let year = today.getFullYear();
    let month = today.getMonth() + 1 ;
    let date = today.getDate();
    resp.send( `今天是${year}年${month}月${date}日`);
}

app.use( handler );

app.listen( port , ()=> console.log( '正在监听' ) );